<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:tn="http://www.w3.org/1999/xhtml"
      xmlns="http://www.w3.org/1999/html">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Users</title>
    <!-- 新 Bootstrap4 核心 CSS 文件 -->
    <link rel="stylesheet"
          href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <!-- bootstrap.bundle.min.js 用于弹窗、提示、下拉菜单，包含了 popper.min.js -->
    <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
    <!-- 最新的 Bootstrap4 核心 JavaScript 文件 -->
    <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
    <script>
        function inNull(str){
            if (str =="")
                return true;
            var regu = "^[]+$";
            var re = new RegExp(regu);
            return re.test(str);
        }
        $(function () {
            $("#divImportExcecel").hide();
            $("#btn4ImportExcecel").click(function () {
                if ($("#divImportExcecel").is(":hidden"))
                    $("#divImportExcecel").show();
                else
                    $("#divImportExcecel").hide();
            });

            $("#btn4ExportExcecel").click(function () {
                location.href = "./exportExcel";
            });

            $("#div4addUser").hide();
            $("#btn4showhideis").click(function () {
                if ($("#div4addUser").is(":hidden"))
                    $("div4addUser").show();
                else
                    $("#div4addUser").hide();
            });
            $("#add").click(function () {
                var nameVal = $("#name").val();
                var pwdVal = $("pwd").val();
                var roleVal = $("#role option:selected").text();
                if (isNull(nameVal) || isNull(pwdVal) || isNull(roleVal)) {
                    confirm("请完善信息");
                    return;
                }
                //var userBean = {
                //"name": nameVal,
                //"password": pwdVal,
                //"role": roleVal
                //};
                //$.ajax({
                //type:"POST",
                //url:"/addUser",
                //data: userBean,
                //async: true,
                //success: function (result){
                //alert(result.msg);
                //location.href = "users";
                // }
                //});

            });
            $("#addFile").click(function () {
                $("#fileSpan").append("<input type='file' name'file'>  <a id='delFile' class='delFile' style='cursor: pointer;color: red'>删除该文件</a><br>");

            });
            $("#delFile").click(function () {
                $($(this).next()).remove();
                $($(this).prev()).remove();
                $(this).remove();
            });
            $(".fileSpan").on("click", "delFile", function () {
                $($(this).next()).remove();
                $($(this).prev()).remove();
                $(this).remove();
            });
        });


    </script>
</head>
<body>
<div id="selectResult" class="mx-auto mt-0 w-50">
    <div class="text-center">
        <input id="btn4showide" type="button" value="显示隐藏添加用户">
    </div>
    <div class="text-center">
        <input id="btn4ImportExcecel" type="button" value="ImportExcecel">
        <input id="btn4ExportExcecel" type="button" value="ExportExcecel">
    </div>
</div>
<div class="panel-body text-center" style="display: block;margin: 0 auto"
     id="divImportExcecel">
    <form role="form" action="/importExcel" method="post"
          enctype="multipart/form-data">
        <div class="form-group">
            <label for="exampleInputFile">File input</label>
            <input type="file" id="exampleInputFile"name="myfile">
        </div>
        <button type="submit" class="btn btn-info">导入</button>
    </form>
</div>
<div id="div4addUser" class="mx-auto mt-0 w-50 border border-success">
    <div class="text-center">
        <label>添加用户</label>
    </div>
</div>
<form name="addUser" action="addUser" method="post" enctype="multipart/form-data">
    <div class="form-group">
        <label for="name">name:</label>
        <input type="text" class="form-control" name="name" id="name">
    </div>
    <div class="form-group">
        <label for="password">Password:</label>
        <input type="password" class="form-control" name="password" id="password">
    </div>
    <div class="form-group">
        <label for="role">role:</label>
        <select class="form-control" name="role" id="role">
            <option>admin</option>
            <option>user</option>
        </select>
    </div>
    <div class="form-group">
        <span id="fileSpan" class="fileSpan">
            <input type="file" name="file"><a id="delFile" class='delFile' style="...">删除该文件</a><br>
        </span>
        <a id="addFile" style="...">添加该文件</a>
    </div>
    <div class="text-center">
        <input id="add" type="submit" value="添加用户"/>
    </div>
</form>

</body>

<body>
<div id="selectResult2" style="width: 50%;margin: 0 auto">
    <table class="table table-white table-hover">
        <thead>
        <tr>
            <th>用户id</th>
            <th>用户名称</th>
            <th>用户密码</th>
            <th>用户权限</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <tr th:each="user:${userList}">
            <td tn:text="${user.id}"></td>
            <td th:text="${user.name}"></td>
            <td th:text="${user.password}"></td>
            <td th:text="${user.role}"></td>
            <td>
                <a th:href="@{/user/{id}(id=${user.id})}">修改</a>
                <a th:href="@{/deleteUser/{id}(id=${user.id})}"id="delete">删除</a>
        </tr>
        </tbody>
    </table>
    <!--显示分页信息部分代码-->
    <div class="modal-footer no-margin-top">
    <div>
        <strong>当前第 [[${pageInfo.pageNum}]]页，共[[${pageInfo.pages}]] 页.一共 [[${pageInfo.total}]] 条记录
        </strong>
    </div>
    <ul class="pagination pill-right no-margin">
        <li th:if="${pageInfo.hasPreviousPage}">
            <a th:href="'user?pageNum=1'">首页</a>
        </li>
        <li class="prev" th:if="${pageInfo.hasPreviousPage}">
            <a th:if="'users?pageNum='+${pageInfo.prePage}">
                <i class="ace-icon fa fa-angle-double-left"></i>
            </a>
        </li>
        <li th:each="nav:${pageInfo.navigatepageNums}">
            <a th:href="'users?pageNum='+${nav}" th:text="${nav}" th:if="${nav != pageInfo.pageNum}"></a>
            <span style="..." th:if="${nav == pageInfo.pageNum}" th:text="${nav}"></span>
        </li>
        <li class="next" th:if="${pageInfo.hasNextPage}">
            <a th:href="'user?pageNum='+${pageInfo.nextPage}">
                <i class="ace-icon fa-angle-double-right"></i>
            </a>
        </li>
        <li>
            <a th:href="'users?pageNum'+${pageInfo.pages}">尾页</a>
        </li>
    </ul>
</div>
</div>

</body>

</html>